package ${package.Controller};

import com.hfepay.common.core.bean.Result;
import com.hfepay.common.data.mybatis.bean.QueryPage;
import ${package.Entity}.${entity};
import ${cfg.parentPackage}.domain.${entity}DO;
import ${package.Service}.${table.serviceName};
import ${cfg.parentPackage}.query.${entity}Query;
import com.hfepay.common.core.bean.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;


/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Slf4j
@RestController
@RequestMapping("/ai/${table.entityPath}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    private ${entity}Service ${table.entityPath}Service;

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<${entity}DO> get(@PathVariable Long id) {
        return ${table.entityPath}Service.selectById(id);
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id){
        return ${table.entityPath}Service.deleteById(id);
    }

    /**
     * 添加
     * @param ${table.entityPath}
     * @return
     */
    @PostMapping
    public Result insert(@RequestBody ${entity} ${table.entityPath}){
        return ${table.entityPath}Service.insert(${table.entityPath});
    }

    /**
     * 修改
     * @param ${table.entityPath}
     * @return
     */
    @PutMapping
    public Result update(@RequestBody ${entity} ${table.entityPath}){
        return ${table.entityPath}Service.update(${table.entityPath});
    }

    /**
     * 分页查询
     * @param current   查询页
     * @param size   每页显示条数
     * @param query 查询参数
     * @return
     */
    @GetMapping("/page")
    public Result<Page<${entity}DO>> page(Integer current,Integer size, ${entity}Query query){
        return ${table.entityPath}Service.page(new QueryPage(current,size),query);
    }


}
</#if>
